
(function ($) {
 
    $.fn.animatedModal = function(options) {
        var modal = $(this);
    
        //Defaults
        var settings = $.extend({
            modalTarget:'animatedModal', 
            position:'fixed', 
            width:'100%', 
            height:'100%', 
            top:'0px', 
            left:'0px', 
            zIndexIn: '9999',  
            zIndexOut: '-9999',  
            color: '#000', 
            opacityIn:'1',  
            opacityOut:'0', 
            animatedIn:'zoomIn',
            animatedOut:'zoomOut',
            animationDuration:'.6s', 
            overflow:'hidden', 
            // Callbacks
            beforeOpen: function() {
            	
            	
            },           
            afterOpen: function() {
            
            }, 
            beforeClose: function() {}, 
            afterClose: function() {
            	$('.modal-content').html('');
            }
            //position: fixed; width: 100%; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); overflow-y: hidden; z-index: 9999; opacity: 1;
            

        }, options);
        
        var closeBt = $('.close-'+settings.modalTarget);

        //console.log(closeBt)

        var href = $(modal).attr('href'),
            id = $('body').find('#'+settings.modalTarget),
            idConc = '#'+id.attr('id');
            //console.log(idConc);
            // Default Classes
            id.addClass('animated');
            id.addClass(settings.modalTarget+'-off');

        //Init styles
        var initStyles = {
            'position':settings.position,
            'width':settings.width,
            'height':settings.height,
            'top':settings.top,
            'left':settings.left,
            'background-color':'#2B2B2B',
            'overflow-y':settings.overflow,
            'z-index':settings.zIndexOut,
            'opacity':settings.opacityOut,
            '-webkit-animation-duration':settings.animationDuration
        };
        var buttonStyles = {
        	'background-color': settings.color,
        	'height':'46px',
        	//'opacity':'0.8',
        		
        }
        //Apply stles
        id.css(initStyles);
        closeBt.css(buttonStyles);
        		
        modal.click(function(event) {       
            event.preventDefault();
           // alert(event.target.id);
            $('.modal-content').html('');
            
            $('body, html').css({'overflow':'hidden'});
            if (href == idConc) {
                if (id.hasClass(settings.modalTarget+'-off')) {
                    id.removeClass(settings.animatedOut);
                    id.removeClass(settings.modalTarget+'-off');
                    id.addClass(settings.modalTarget+'-on');
                } 

                 if (id.hasClass(settings.modalTarget+'-on')) {
                	 
                    //settings.beforeOpen();
                	 //alert($(event.target).text());
                	 $('#viewmodeDownload').attr("href","/download/f/"+event.target.id.toString());
                	 $('#nameViewFile').text($(event.target).text());
                	 var fileExtension = getFileExtension($(event.target).text());
                	 fileExtension = fileExtension.toString().toLowerCase();
                	 
                	 var thisClick = $(event.target);
                	 var urlImage = thisClick.attr('contextmenu');
                	 
                	// console.log(event.target.contextmenu.toString() +event.target.id.toString());
                	 
                	 if(fileExtension == "png"|| fileExtension == "jpg" ||fileExtension == "jpeg"){
                		 $('.modal-content').append(function () {
                			 var imageContent = '<div class="imagebox"><img class="imageshow" src="'+urlImage+'" alt=""> </img></div>';
                			 return imageContent; 
         				});
                	 }
                	 
                	 if(fileExtension == "pdf"|| fileExtension == "doc" ||fileExtension == "docx" 
                		|| fileExtension == "xls" || fileExtension == "xlsx" || fileExtension == "ppt"
                		|| fileExtension == "ppt" || fileExtension == "pptx" || fileExtension == "txt"
                	 ){
                		 $(event.target).gdocsViewer();
                	 } else {
                		 $('.modal-content').append(function () {
                			 var downloadContent = '<div class="downloadbox"><p>No preview available</p><a href="/download/f/'+event.target.id.toString()+'" id="">Download</a> </div>';
                			 return downloadContent; 
         				});
                	 }
                	 
                	 
                    id.css({'opacity':settings.opacityIn,'z-index':settings.zIndexIn});
                    id.addClass(settings.animatedIn);  
                    id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterOpen);
                };  
            } 
        });

        closeBt.click(function(event) {
            event.preventDefault();
            $('body, html').css({'overflow':'auto'});

            settings.beforeClose(); //beforeClose
            if (id.hasClass(settings.modalTarget+'-on')) {
                id.removeClass(settings.modalTarget+'-on');
                id.addClass(settings.modalTarget+'-off');
            } 

            if (id.hasClass(settings.modalTarget+'-off')) {
                id.removeClass(settings.animatedIn);
                id.addClass(settings.animatedOut);
                id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterClose);
            };

        });

        function afterClose () {       
            id.css({'z-index':settings.zIndexOut});
            settings.afterClose(); //afterClose
        }

        function afterOpen () {       
            settings.afterOpen(); //afterOpen
        }

    }; // End animatedModal.js

}(jQuery));





/*

(function ($) {
 
    $.fn.animatedModal = function(options) {
        var modal = $(this);
    
        //Defaults
        var settings = $.extend({
            modalTarget:'animatedModal', 
            position:'fixed', 
            width:'100%', 
            height:'100%', 
            top:'0px', 
            left:'0px', 
            zIndexIn: '9999',  
            zIndexOut: '-9999',  
            color: '#000', 
            opacityIn:'1',  
            opacityOut:'0', 
            animatedIn:'zoomIn',
            animatedOut:'zoomOut',
            animationDuration:'.6s', 
            overflow:'hidden', 
            // Callbacks
            beforeOpen: function() {
            	
            	
            },           
            afterOpen: function() {
            
            }, 
            beforeClose: function() {}, 
            afterClose: function() {
            	$('.modal-content').html('');
            }
            //position: fixed; width: 100%; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); overflow-y: hidden; z-index: 9999; opacity: 1;
            

        }, options);
        
        var closeBt = $('.close-'+settings.modalTarget);

        //console.log(closeBt)

        var href = $(modal).attr('href'),
            id = $('body').find('#'+settings.modalTarget),
            idConc = '#'+id.attr('id');
            //console.log(idConc);
            // Default Classes
            id.addClass('animated');
            id.addClass(settings.modalTarget+'-off');

        //Init styles
        var initStyles = {
            'position':settings.position,
            'width':settings.width,
            'height':settings.height,
            'top':settings.top,
            'left':settings.left,
            'background-color':'#2B2B2B',
            'overflow-y':settings.overflow,
            'z-index':settings.zIndexOut,
            'opacity':settings.opacityOut,
            '-webkit-animation-duration':settings.animationDuration
        };
        var buttonStyles = {
        	'background-color': settings.color,
        	'height':'46px',
        	//'opacity':'0.8',
        		
        }
        //Apply stles
        id.css(initStyles);
        closeBt.css(buttonStyles);
        		
        modal.click(function(event) {       
            event.preventDefault();
           // alert(event.target.id);
            $('.modal-content').html('');
            
            $('body, html').css({'overflow':'hidden'});
            if (href == idConc) {
                if (id.hasClass(settings.modalTarget+'-off')) {
                    id.removeClass(settings.animatedOut);
                    id.removeClass(settings.modalTarget+'-off');
                    id.addClass(settings.modalTarget+'-on');
                } 

                 if (id.hasClass(settings.modalTarget+'-on')) {
                	 
                    //settings.beforeOpen();
                	 //alert($(event.target).text());
                	 $('#viewmodeDownload').attr("href",event.target.id.toString());
                	 $('#nameViewFile').text($(event.target).text());
                	 document.title = $(event.target).text();
                	 var fileExtension = getFileExtension($(event.target).text());
                	// fileExtension = fileExtension.toString().toLowerCase();
                	 
                	 if(fileExtension == "pdf"|| fileExtension == "doc" ||fileExtension == "docx" 
                		|| fileExtension == "xls" || fileExtension == "xlsx" || fileExtension == "ppt"
                		|| fileExtension == "ppt" || fileExtension == "pptx" || fileExtension == "txt" ){
                		 $(event.target).gdocsViewer();
                	 } 
                	                	 
	                	else {
	                		 $('.modal-content').append(function () {
	                			 var downloadContent = '<div class="downloadbox"><p>No preview available</p><a href="'+event.target.id.toString()+'" id="">Download</a> </div>';
	                			 return downloadContent; 
	         				});
	                	}
                	 
                	 
                    id.css({'opacity':settings.opacityIn,'z-index':settings.zIndexIn});
                    id.addClass(settings.animatedIn);  
                    id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterOpen);
                };  
            } 
        });

        closeBt.click(function(event) {
            event.preventDefault();
            $('body, html').css({'overflow':'auto'});

            settings.beforeClose(); //beforeClose
            if (id.hasClass(settings.modalTarget+'-on')) {
                id.removeClass(settings.modalTarget+'-on');
                id.addClass(settings.modalTarget+'-off');
            } 

            if (id.hasClass(settings.modalTarget+'-off')) {
                id.removeClass(settings.animatedIn);
                id.addClass(settings.animatedOut);
                id.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', afterClose);
            };

        });

        function afterClose () {       
            id.css({'z-index':settings.zIndexOut});
            settings.afterClose(); //afterClose
        }

        function afterOpen () {       
            settings.afterOpen(); //afterOpen
        }

    }; // End animatedModal.js

}(jQuery));



*/